package cn.cdeden.knowledge.controller.filesDistribute;

import cn.cdeden.common.core.domain.R;
import cn.cdeden.knowledge.domain.dto.FilesDistributeDto;
import cn.cdeden.knowledge.domain.dto.FilesDistributeQueryParam;
import cn.cdeden.knowledge.domain.dto.RecoverFileChooseAPath;
import cn.cdeden.knowledge.service.FilesDistributeService;
import io.undertow.util.BadRequestException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 分发和接收管理
 */
@Controller
@Slf4j
//@Api(tags = "分发和接收管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/filesDistribute")
public class FilesDistributeController {

    private final FilesDistributeService filesDistributeService;

    /**
     * 查询分发
     * @param query
     * @param pageable
     * @return
     */
//    @Log("查询分发")
//    @ApiOperation("查询分发")
    @GetMapping(value = "/queryDistribute")
//    @ResponseBody
    public R queryDistribute(FilesDistributeQueryParam query, Pageable pageable){
        return R.ok(filesDistributeService.queryDistribute(query,pageable));
//        return BaseRespResult.successResult(filesDistributeService.queryDistribute(query,pageable));
    }


    /**
     * 查询接收
     * @param query
     * @param pageable
     * @return
     */
//    @Log("查询接收")
//    @ApiOperation("查询接收")
    @GetMapping(value = "/querySend")
    @ResponseBody
    public R querySend(FilesDistributeQueryParam query, Pageable pageable){
        return R.ok(filesDistributeService.querySend(query,pageable));
//        return BaseRespResult.successResult(filesDistributeService.querySend(query,pageable));
    }


    /**
     * 撤回分发
     * @param id
     * @return
     */
//    @Log("撤回分发")
    @GetMapping(value = "/delete")
//    @ApiOperation("撤回分发")
    @ResponseBody
    public R delete(Integer id) {
        return R.ok(filesDistributeService.removeById(id));
//        return BaseRespResult.successResult(filesDistributeService.removeById(id));
    }


    /**
     * 接收文件
     * @param recoverFileChooseAPath
     * @return
     */
//    @Log("接收文件")
//    @ApiOperation("接收文件")
    @PostMapping(value = "/receiveFile")
    @ResponseBody
    public R receiveFile(@RequestBody RecoverFileChooseAPath recoverFileChooseAPath) throws BadRequestException {
        boolean b = filesDistributeService.receiveFile(recoverFileChooseAPath);
        if (b){
            return R.ok("成功保存到个人库");
//            return BaseRespResult.successResult("成功保存到个人库");
        }
        return R.fail("保存失败");
    }


    /**
     * 分发给同事
     * @param resources
     * @return
     */
    @PostMapping
//    @Log("分发给同事")
//    @ApiOperation("分发给同事")
    @ResponseBody
    public R distribute(@RequestBody FilesDistributeDto resources) throws BadRequestException {
        return R.ok(filesDistributeService.insert(resources));
//        return BaseRespResult.successResult(filesDistributeService.insert(resources));
    }




}
